package com.client.clovece;
import javax.swing.ImageIcon;


public class Player {
	//aktualni pozice figurek v poli grid, tridy GamePanel
	private Figure p[];
	private boolean plInControl = true;
	private LocalGame parent;
	private ButtonStates id;
	private int attempts = 0;
	ImageIcon ico;
	
	public Player(boolean control, ButtonStates id/*, String pathToImg*/){
		this.parent = parent;
		plInControl = control;
		Configuration c = Configuration.getInstance();
		//returns the info state from the players id and picks an equivalent path in configuration to init an icon
		//System.out.println("ID je " + id.ordinal() + " INFO je " + ButtonStates.toInfo(id).ordinal() + " CESTA je " + c.getPath(ButtonStates.toInfo(id)));
		ico = new ImageIcon(c.getPath(ButtonStates.toInfo(id)));
		p = new Figure[4];
		this.id = id;
		initp();
	}
	
	private void initp(){
		for(int i = 0; i< 4; i++){
			
			p[i] = new Figure();
		}
	} 
	
	public Figure getFigure(int index){
		if(index < 4) return p[index];
		return null;
	}
	//!TODO boundaries
	public void setTokenStart(int token, int index){
		p[token].setPos(index);
	}
	
	public void setTokenPos(int before, int then){
		for(int i=0; i<4; i++){
			if(p[i].getPos() == before) p[i].setPos(then);
		}
	}
	
	public void setTokenDist(int position, int diceValue){
		for(int i=0; i<4; i++){
			if(p[i].getPos() == position) p[i].setDist(diceValue);
		}
	}
	
	public void addTokenDist(int position, int diceValue){
		for(int i=0; i<4; i++){
			if(p[i].getPos() == position) p[i].addDist(diceValue);
		}
	}
	
	public void setTokenPos(int before, int then, int dice){
		for(int i=0; i<4; i++){
			if(p[i].getPos() == before){
				p[i].setPos(then);
				p[i].addDist(dice);
			}
		}
	}
	
	public int getTokenDist(int position){
		for(int i=0; i<4; i++){
			if(p[i].getPos() == position) return p[i].getDist();
		} 
		return -1;
	}
	
	
	
	public void setControl(boolean playerControls){
		plInControl = playerControls;
	}
	
	public boolean getControl(){
		return plInControl;
	}
	
	public ButtonStates getId(){
		return id;
	}
	
	public int getIndex(){
		return id.ordinal();
	}
	public ImageIcon getImg(){
		return ico;
	}
	
	public int getAttempts(){
		return attempts;
	}
	
	public void nullAttempts(){
		attempts = 0;
	}
	
	public void incAttempts(){
		attempts ++;
	}
	
}
